/**
 * Created by Administrator on 2016/4/14.
 */
(function (window,document) {
    var w = window,
        doc = document;
    var Kodo = function (selector) {
        return new Kodo.prototype.init(selector);
    }
    Kodo.prototype = {
        constructor : Kodo, //对象的constructor属性返回创建该对象的函数的引用。
        length : 0,
        splice : [].splice, //使对象变成类数组
        selector : '',
        init : function (selector) {
            //dom选择的一些判断
        },
        hasClass:function (cls) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');  //$匹配结尾     \s	匹配任意的空白符
            for(var i=0;i<this.length;i++){
                if(this[i].className.match(reg)) return true;
                return false;
            }
            return this;
        },
        addClass : function(cls) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
            for (var i = 0; i < this.length; i++) {
                if(!this[i].className.match(reg))
                    this[i].className += ' ' + cls;
            }
            return this;
        },
        removeClass : function(cls) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
            for (var i = 0; i < this.length; i++) {
                if (this[i].className.match(reg))
                    this[i].className = this[i].className.replace(cls,'');
            }
            return this;
        },
        css : function(attr,val) {//链式测试
            console.log(this.length);
            for(var i = 0;i < this.length; i++) {
                if(arguments.length == 1) {
                    return getComputedStyle(this[i],null)[attr];
                }
                this[i].style[attr] = val;
            }
            return this;
        }

    }
    Kodo.prototype.init.prototype = Kodo.prototype;

    Kodo.ajax = function () {   //直接挂载方法，可K.ajax调用
        console.log(this);
    }

    window.K = Kodo;
})(window,document);